import {ActionContext, Module} from 'vuex';
import Cache from '@/store/entities/administration/maintenance/cache';
import Ajax from '@/lib/ajax';

interface ListState<T> {
    list: T[];
    loading: boolean;
}

class CacheModule implements Module<ListState<Cache>, any> {
    namespaced = true;
    state = {
        list: new Array<Cache>(),
        loading: false,
    };
    actions = {
        async getAllCaches(context: ActionContext<ListState<Cache>, any>, payload: any) {
            context.state.loading = true;
            const response = await Ajax.get('/api/services/app/Caching/GetAllCaches');
            context.state.loading = false;
            context.state.list = response.data.result.items;
        },
        async clearCache(context: ActionContext<ListState<Cache>, any>, payload: any) {
            await Ajax.post('/api/services/app/Caching/ClearCache', payload.data);
        },
        async clearAllCaches(context: ActionContext<ListState<Cache>, any>, payload: any) {
            await Ajax.post('/api/services/app/Caching/ClearAllCaches');
        },
    };
}

const cacheModule = new CacheModule();
export default cacheModule;